package org.lib.adapter.web.controller;

import java.util.Objects;

import org.lib.data.user.api.dto.AddUserDTO;
import org.lib.data.user.api.feign.UserFeign;
import org.lib.data.user.api.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;

/**
 * 用户接口
 * @author ben
 * @date 2021-08-30 22:44:19 CST
 */
@RestController
@RequestMapping(value="/user")
@Slf4j
public class UserController {

	@Autowired
	private UserFeign userFeign;

	/**
	 * 添加用户
	 * @author ben
	 * @date 2021-08-30 22:46:04 CST
	 * @param dto
	 * @return 成功返回新增用户id
	 */
	@PostMapping(value="/add")
	public Long addUser(@RequestBody AddUserDTO dto) {
		log.info("添加用户-适配层：dto={}", dto);
		return userFeign.addUser(dto);
	}
	
	@GetMapping(value="/get")
	public UserVO getUser(@RequestParam Long id) {
		if (Objects.isNull(id) || id < 1) {
			return null;
		}
		log.info("getUser, id={}", id);
		return userFeign.getUser(id);
	}
	
}
